package cn.dataling.ai.config;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatModelConfig {

    @Resource
    private JdbcChatMemory jdbcChatMemory;
    @Value("${model.prompt}")
    private String modelPrompt;


    @Bean("ollamaChatClient")
    public ChatClient ollamaChatClient(OllamaChatModel ollamaChatModel) {

        return ChatClient.builder(ollamaChatModel)
                .defaultSystem(modelPrompt)
                .defaultAdvisors(
                        new MessageChatMemoryAdvisor(jdbcChatMemory) // chat-memory advisor
                )
                .build();
    }

    @Bean("openAiChatClient")
    public ChatClient openAiChatClient(OpenAiChatModel openAiChatModel) {

        return ChatClient.builder(openAiChatModel)
                .defaultSystem(modelPrompt)
                .defaultAdvisors(
                        new MessageChatMemoryAdvisor(jdbcChatMemory) // chat-memory advisor
                )
                .build();
    }
}
